package com.jr.dao.impl;

import com.jr.dao.IProjectInfoDao;
import com.jr.pojo.ProjectInfo;
import util.DBHelper;

import java.util.ArrayList;

public class ProjectInfoDaoImpl implements IProjectInfoDao {
    private util.DBHelper db = new DBHelper();

    @Override
    public ArrayList<ProjectInfo> selectByStatus(Integer status) {
        StringBuilder str = new StringBuilder("select * from projectinfo where 1=1");
        if (status >=0 && status<=2) {
            str.append(" and status="+status);
        }
        return  db.dtQuery(str.toString(),ProjectInfo.class);
    }

    @Override
    public ArrayList<ProjectInfo> selectByPid(Integer pid) {
       String sql = "select * from projectinfo where pid=?";
       return db.dtQuery(sql,ProjectInfo.class,pid);
    }

    @Override
    public int updateProject(ProjectInfo pro) {
       String sql = "update projectinfo set status=? where pid=?";
       Object[] objs = {pro.getStatus(),pro.getPid()};
       return db.dtUpdate(sql,objs);
    }
}
